package branch.feature.coco_camera

import androidx.appcompat.app.AppCompatActivity
import okio.IOException
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date

// ref link: https://github.com/soulqw/CoCo/blob/master/app/src/main/java/com/qw/soulphototaker/BaseToolbarActivity.kt#L9
open class BaseToolbarActivity : AppCompatActivity() {
    @Throws(IOException::class)
    fun createSDCardFile(): File {
        // create an image file name
        val timestamp: String = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())

        val storageDir = File(externalCacheDir!!.path + "/" + timestamp)

        if (!storageDir.exists()) {
            storageDir.mkdir()
        }

        return File.createTempFile(
            "JPEG_${timestamp}_coco_camera", // file name prefix
            ".jpg", // extension
            storageDir
        )
    }

    @Throws(IOException::class)
    fun createSDCardFile(filename: String?): File {
        // create an image with filename
        val storageDir = File(externalCacheDir!!.path + "/" + filename)
        if (!storageDir.exists()) {
            storageDir.mkdir()
        }

        return File.createTempFile(
            "JPEG_test",
            ".jpg",
            storageDir
        )
    }
}